# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Mirco Tischler <mt-ml at gmx dot de>

pkgname=ostree
_commit=ecd00a3e1977c9193ea0b27669234fa5669dfe7c  # tags/v2023.2
pkgver=2023.2
pkgrel=1
pkgdesc="Operating system and container binary deployment and upgrades"
url="https://ostreedev.github.io/ostree/"
arch=(x86_64)
license=(custom:LGPL2)
depends=(
  bash
  fuse3
  gcc-libs
  glibc
  libgpg-error
  libsodium
  sh
  util-linux
  zlib
)
makedepends=(
  avahi
  curl
  e2fsprogs
  git
  glib2
  gobject-introspection
  gpgme
  gtk-doc
  libarchive
  libsoup
  libxslt
  mkinitcpio
  openssl
  python
  systemd
  xz
)
checkdepends=(
  cpio
  elfutils
  gjs
  parallel
  python-yaml
  syslinux
)
provides=(libostree-1.so)
source=(
  git+https://github.com/ostreedev/ostree#tag=$_commit
  git+https://github.com/mendsley/bsdiff
  git+https://gitlab.gnome.org/GNOME/libglnx.git
  $pkgname-2023.1-use_fuse3.patch
)
b2sums=('SKIP'
        'SKIP'
        'SKIP'
        'cfff162120f70995e18ec56454711501391b97456e2a0f34643c9d2a9c2b50b4d76afc2e2fc50ea28e8a773c618215d6cb855b96663f69dc5cc93bc5766f3f28')
# upstream ticket about chain of trust:
# https://github.com/ostreedev/ostree/issues/2349
validpgpkeys=('1CEC7A9DF7DA85ABEF843DC0A866D7CCAE087291') # Colin Walters <walters@redhat.com>

prepare() {
  cd $pkgname

  # Fixes for GLib 2.76
  git cherry-pick -n 376c9d7effa01fa020711a3f12829fe9b18b8bca \
                     813c439352297622e74a288aadf3cd700d19bc2f

  # use fusemount3 (fuse3)
  git apply -3 ../$pkgname-2023.1-use_fuse3.patch

  # remove failing test: https://github.com/ostreedev/ostree/issues/2790
  sed -e '/test-signed-pull-summary.sh/d' -i Makefile-tests.am

  git submodule init
  git submodule set-url bsdiff "$srcdir/bsdiff"
  git submodule set-url libglnx "$srcdir/libglnx"
  git -c protocol.file.allow=always submodule update

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --localstatedir=/var
    --sbindir=/usr/bin
    --libexecdir=/usr/lib
    --disable-static
    --enable-experimental-api
    --enable-gtk-doc
    --with-builtin-grub2-mkconfig
    --with-curl
    --with-dracut
    --with-ed25519-libsodium
    --with-mkinitcpio
    --with-openssl
  )

  cd $pkgname
  ./configure "${configure_options[@]}"
  # prevent overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  make check -k -C $pkgname
}

package() {
  depends+=(
    avahi libavahi-client.so libavahi-common.so libavahi-glib.so
    curl libcurl.so
    glib2 libgio-2.0.so libglib-2.0.so libgobject-2.0.so
    gpgme libgpgme.so
    libarchive libarchive.so
    libsoup libsoup-2.4.so
    openssl libcrypto.so
    systemd-libs libsystemd.so
    xz liblzma.so
  )

  make DESTDIR="$pkgdir" install -C $pkgname
  install -vDm 644 $pkgname/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
}
